package books.storage.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@Table(name = "AUTHORS")
public class AuthorEntity extends books.storage.util.jpa.Entity implements
		Serializable {

	private static final long serialVersionUID = -6994057122826574986L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Integer id;

	@Column(nullable = false, unique = true)
	private String name;

	@Temporal(TemporalType.DATE)
	@Column(nullable = false)
	private Date birthday;

	@Temporal(TemporalType.DATE)
	@Column(nullable = true)
	private Date deathday;

	@OneToMany(mappedBy = "author")
	private List<BookEntity> books;

	public AuthorEntity() {
	}

	/**
	 * @return the id
	 */
	public Integer getId() {
		return id;
	}

	/**
	 * @param id
	 *            the id to set
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name
	 *            the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the age
	 */
	public int getAge() {
		Date today = new Date();
		return today.compareTo(this.getBirthday());
	}

	/**
	 * @return the birthday
	 */
	public Date getBirthday() {
		return birthday;
	}

	/**
	 * @param birthday
	 *            the birthday to set
	 */
	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}

	/**
	 * @return the deathday
	 */
	public Date getDeathday() {
		return deathday;
	}

	/**
	 * @param deathday
	 *            the deathday to set
	 */
	public void setDeathday(Date deathday) {
		this.deathday = deathday;
	}

	/**
	 * @return the books
	 */
	public List<BookEntity> getBooks() {
		return books;
	}

	/**
	 * @param books
	 *            the books to set
	 */
	public void setBooks(List<BookEntity> books) {
		this.books = books;
	}

}